<?php

namespace IDock\Insurance\ACIC\Request;

use Exception;
use IDock\Insurance\ACIC\ACICEnums;
use IDock\Insurance\ACIC\Response\UploadFileResponse;
use IDock\Visitor\UploadFileVisitor;

class UploadFileRequest extends AllACICRequest
{
    protected $code = 'V09';

    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像资料上传';

    /**
     * @var UploadFileVisitor $visitor
     */
    protected $visitor;

    /**
     * @return array
     * @throws Exception
     */
    public function generate(): array
    {
        $inquiryNo = $this->visitor->biInquiryNo;
        if (!$inquiryNo) {
            $inquiryNo = $this->visitor->ciInquiryNo;
        }
        $fileList = [];

        foreach ($this->visitor->getFileList() as $value) {
            $fileList[] = [
                'FileType' => ACICEnums::$uploadFileType[$value['type']],
                'FileURL' => $value['url'] ?? '',
            ];
        }

        return [
            'QueryNo' => $inquiryNo,
            'MFileList' => ['MFileItem' => $fileList],
        ];
    }
}